Originally Posted by
quzah
C doesn't keep you from wandering around in memory you shouldn't be wandering in. You have to do that yourself.
Quzah.
I see!
my means is that how to test one data structure whether be defined.( how to test the data which will be printed whether is out of memory )
Code:
char *string = (char*) malloc ( 100*sizeof(char));
// 1000 is my on purpose, though 100 is defined.
for ( int i = 0; i < 1000; ++i )
{
//my test code is that,but I don't know whether is right
if ( string[i] )
{
printf("%c,",string[i]);
} else
{
printf("error of memory.\n"); exit(1);
}
}